package com.nf.health.app.intervention_details.fragment;

import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.google.gson.Gson;
import com.nf.health.app.Constants;
import com.nf.health.app.R;
import com.nf.health.app.core.MyGsonBuilder;
import com.nf.health.app.fragment.IBaseFragment;
import com.nf.health.app.http.Act;
import com.nf.health.app.intervention_details.adapter.DoctorOrderDetailsAdapter;
import com.nf.health.app.intervention_details.bean.DoctorOrderDetailsBean;
import com.nf.health.app.utils.ViewUtil;

/**
 * 医嘱方案详情fragment
 * Created by Administrator on 2016/11/10.
 */
public class DoctorOrderDetailsFragment extends IBaseFragment {
    private RecyclerView mRecyclerView;
    private DoctorOrderDetailsAdapter mDoctorOrderDetailsAdapter;
    private DoctorOrderDetailsBean mDoctorOrderDetailsBean;
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        addViewFillInRoot(R.layout.common_layout_recycler);

        mRecyclerView = ViewUtil.getView(rootView, R.id.recycler_view_common);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        initData();
    }
    private void initData(){
        provider.getInterveneDoctorAdvice(Constants.CHANGE_ABLE.INTERVENTION_ID);
    }
    @Override
    public void handleActionSuccess(String actionName, Object object) {
        if(actionName.equals(Act.Flag.GET_INTERVENE_DOCTOR_ADVICE)){
            Gson gson = new MyGsonBuilder().createGson();
            mDoctorOrderDetailsBean = gson.fromJson(object+"",DoctorOrderDetailsBean.class);
            if(mDoctorOrderDetailsBean == null){
                return;
            }
            mDoctorOrderDetailsAdapter = new DoctorOrderDetailsAdapter(getContext(),mDoctorOrderDetailsBean);
            mRecyclerView.setAdapter(mDoctorOrderDetailsAdapter);
        }
    }
}
